package org.alanlau.springredis.service;

import org.alanlau.springredis.entity.Person;
import org.alanlau.springredis.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Service层
 *
 * @author Alan
 * @data 2019/10/13 20:08
 */
@Service
public class PersonService {
    @Autowired
    private PersonRepository personRepository;

    public List<Person> getPersons() {
        Iterable<Person> persons = personRepository.findAll();
        List<Person> datas = new ArrayList<>();
        persons.forEach(person -> datas.add(person));

        return datas;
    }

    public void save(Person person) {
        personRepository.save(person);
    }

    public List<Person> getPersonByName(String name){
        return personRepository.findByName(name);
    }
}
